package com.huike.contract.service.impl;

import com.huike.business.mapper.TbBusinessMapper;
import com.huike.clues.domain.TbAssignRecord;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbRulePool;
import com.huike.clues.mapper.SysUserMapper;
import com.huike.clues.mapper.TbAssignRecordMapper;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.service.ISysUserService;
import com.huike.clues.service.ITbRulePoolService;
import com.huike.clues.service.impl.TbAssignRecordServiceImpl;
import com.huike.clues.utils.HuiKeCrmDateUtils;
import com.huike.clues.utils.JobUtils;
import com.huike.common.constant.Constants;
import com.huike.common.core.domain.entity.SysUser;
import com.huike.common.utils.DateUtils;
import com.huike.contract.domain.vo.TransferVo;
import com.huike.contract.service.ITransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TransferServiceImpl implements ITransferService {

    @Autowired
    private ISysUserService userService;

    @Autowired
    private TbAssignRecordMapper assignRecordMapper;

    @Autowired
    private ITbRulePoolService rulePoolService;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private TbClueMapper clueMapper;


    @Autowired
    private TbBusinessMapper businessMapper;


    /**转派列表*/
    @Override
    //整个TransferVo可以装下 一条数据
    //因为分页是查看多条 所以显示多条数据 根据前端传过来的user对象查询
    public List<TransferVo> list(SysUser user) {
        //根据前端先查到所有user对象
        List<SysUser> sysUsers = userService.selectUserList(user);
        List<TransferVo> list = new ArrayList<>();
        //遍历user集合 把需要的字段装填到我们查询需要的TransferVo对象里面，每装填一次就添加进list集合里面
        for (SysUser sysUser : sysUsers) {
            TransferVo transferVo = new TransferVo();
            //根据user_id查询出cluesNum 线索的count数 每个用户所记录的线索数
            int cluesNum = assignRecordMapper.countAssignCluesByUser(sysUser.getUserId());
            //根据user_id查询出businessNum 商机的统计 每个用户所记录的商机数
            int businessNum = assignRecordMapper.countAssignBusinessByUser(sysUser.getUserId());
            transferVo.setUserId(sysUser.getUserId());
            transferVo.setUserName(sysUser.getUserName());
            transferVo.setPhonenumber(sysUser.getPhonenumber());
            transferVo.setClueNum(cluesNum);
            transferVo.setBusinessNum(businessNum);
            transferVo.setCreateTime(sysUser.getCreateTime());
            list.add(transferVo);
        }
        return list;
    }
}
